1. Field of the Invention
The present invention relates to computer programming and, in particular, to a method of exporting functions of a dynamic link library for execution by an application program on a computer.
2. Description of Related Art
Computer operating systems such as OS/2 and Windows utilize dynamic link libraries as executable modules which contain services that application programs may utilize to perform different functions. Each dynamic link library (DLL) module may be written to contain a plurality of functions that may be utilized by different application programs running at the same time.
In addition, dynamic link libraries may be utilized to contain data and hardware such as typeface fonts in the case of the former and device drivers in the case of the latter. The dynamic link library is normally loaded into memory when an application program is running, and is not inserted into the executable file of the application program, such that the application program and dynamic link library are physically distinct.
Normally a programmer who develops a dynamic link library module that exports a plurality of functions has to create an explicit entry for each function exported in the DLL module definition file. In addition to the module definition file, each function must be prototyped, loaded and queried for its address. In the case of DLL software on the OS/2 operating system (available from International Business Machines Corporation) that exports 600 functions, there must be entered 600 lines of program in the module definition file, 600 lines for the function prototype, and 1200 lines for load and address query to the application protocol interface (API). Additionally, there may be another 601 lines of programming to function for error recovery. This may lead to a total of 1202 lines of overhead program.
In addition, the typical prior art DLL module would make over 600 calls to the operating system in order to execute the 600 DLL module functions. Every call to the operating system (also known as the kernel) is costly because of the extra processing time in the ring transition from ring 3 to ring 0 (discussed further below).
A prior art dynamic link library module OLDDLL.C for making available to application programs printing of the greetings Good Morning, Good Afternoon and Good Evening would typically include the following instructions (unless otherwise indicated, all programs herein are written in C programming language):
*/ #define INCL_DOSDATETIME #define INCL_DOSFILEMGR #define INCL_DOSMEMMGR #include&lt;os2.h&gt; #include&lt;stdio.h&gt; #include&lt;io.h&gt; #include&lt;stdlib.h&gt; #include&lt;math.h&gt; Func_A ( ) { printf("Good Morning/n"); } Func_B ( ) { printf("Good Afternoon.backslash.n"); } Func_C ( ) { printf("Good Evening.backslash.n"): }
The DLL module OLDDLL.C as described has three functions, i.e., printing out the separate phrases Good Morning, Good Afternoon and Good Evening, when requested by an application program. These phrases are contained as Function A, Function B and Function C, respectively.
A typical prior art DLL definition file OLDDLL.DEF would include the following instructions:
LIBRARY olddll INITINSTANCE TERMINSTANCE; tells linker to build DLL, not EXE PA1 DATA MULTIPLE NONSHARED PA1 EXPORTS
Func.sub.--A PA2 Func.sub.--B PA2 Func.sub.--C
The file OLDDLL.DEF is the definition file which must be given to the operating system complied at the time the program is to be complied. The lines following EXPORT list every function which may be exported from the DLL, Func_A, Func_B and Func_C. For a DLL file having N functions, there would be N lines of programming in the EXPORT list.
A typical prior art executable application program TESTOLD.C would include the following instructions:
 */ #define INCL_WIN #define INCL_DOS #include &lt;os2.h&gt; /* System Include File */ #include&lt;stdio.h&gt; #include&lt;process.h&gt; #include&lt;stdlib.h&gt; CHAR objbuff [100]; HMODULE hmodScreen; void ( *pfnFunc_A) (void); void ( *pfnFunc_B) (void); void ( *pfnFunc_C) (void); main( ) { APIRET rc"; rc = DosLoadModule (objbuff, 100, "OLDDLL.C", &hmodScreen )"; if(rc) { printf("Error: Loading the DLL.backslash.n"); ErrorHandler( ); cleanup( ); } rc = DosQueryProcAddr (hmodScreen, O, "Func_A", (PFN *)&pfnFunc_A); if(rc) { printf("Error: Query Address for funcA.backslash.n"); ErrorHandler( ); cleanup( ); } rc = DosQueryProcAddr (hmodScreen, O, "Func_B", (PFN *)&pfnFunc_B ); if(rc) { printf("Error: Query Address for funcB.backslash.n"); ErrorHandler( ); cleanup( ); } rc = DosQueryProcAddr (hmodScreen, O, "Func_C", (PFN *)&pfnFunc_C ); if(rc) { printf("Error: Query Address for funcC.backslash.n"); ErrorHandler( ); cleanup( ); } pfnFunc_A( ); pfnFunc_B( ); pfnFunc_C( ); rc=DosFreeModule(hmodScreen); if(rc) printf("Error: DosFreeModule failed rc=%d.backslash.n",rc); } ErrorHandler( ) { ; } cleanup( ) { ; }
The DosLoadModule statement is an API call to the OS/2 operating system kernel to load the DLL "OLDDLL.C". After loading the DLL the return code (rc) is checked. Then the statement DosQueryProcAddr is used to query each of the addresses of the functions A, B and C. Each DosQueryProcAddr is a separate API call to the OS/2 kernel. The application program then is able to use the DosQueryProcAddr by the statement pfnFunc_A, pfnFunc_B or pfnFunc_Cwithin the DLL.
In operating the DLL module, there are a total of four API calls made to the operating system kernel, one to load the DLL and one for each of the three functions within the DLL module. For the example of 600 functions, there would be 601 API calls to the kernel. Likewise, the number of calls to the kernel for a DLL module having N function is N+1.
Accordingly, it is quite complex and costly in terms of computer execution time to increase the number of functions in a DLL available for use by an application program.
Bearing in mind the problems and deficiencies of the prior art, it is therefore an object of the present invention to provide a dynamic link library that provides better performance and fewer program lines to run.
It is another object of the present invention to provide a smaller application program which uses a DLL module.
A further object of the present invention is to provide a smaller module definition file in the DLL.
It is yet another object of the present invention to provide for fewer API calls to the operating system kernel during DLL module use.
A further object of the present invention is to provide improvement in the performance utilizing a DLL module.
Still other objects and advantages of the invention will in part be obvious and will in part be apparent from the specification.